/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.cgb.portal.bo;

import br.cgb.portal.entity.User;
import br.cgb.portal.facade.UserFacade;
import br.cgb.portal.util.EncryptionUtil;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author LUCAS
 */
@Stateless
public class UserBO implements Serializable {

    @EJB
    private UserFacade userFacade;

    public UserFacade getUserFacade() {
        return userFacade;
    }

    public void create(User user) {
        getUserFacade().create(user);
    }

    public void edit(User user) {
        getUserFacade().edit(user);
    }

    public void remove(User user) {
        getUserFacade().remove(user);
    }

    public User find(Object id) {
        return getUserFacade().find(id);
    }

    public List<User> findAll() {
        return getUserFacade().findAll();
    }

    public User findUserPerEmail(String email) {
        return getUserFacade().findUserPerEmail(email);
    }

    public User findUserPerEmailValidated(String email) {
        return getUserFacade().findUserPerEmailValidated(email);
    }

    public boolean authenticateUser(User user) {
        User userAux = getUserFacade().findUserPerEmailValidated(user.getEmail());
        if (userAux != null && EncryptionUtil.auth(user.getPassword(), userAux.getPassword())) {
            return true;
        }
        return false;
    }
}
